﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Hired
{
    public static class DBImage
    {
        public static ImageRoster RetrieveImageByAddress(string URL)
        {
            using (hireddbEntities db = new hireddbEntities())
            {
                return
                    (from i in db.ImageRosters
                     where i.ImageAddress == URL
                     orderby i.Timestamp descending
                     select i).SingleOrDefault();
            }
        }

        public static List<ImageRoster> RetrieveImagesByUserID(string ID)
        {
            using (hireddbEntities db = new hireddbEntities())
            {
                try
                {
                    var imageList =
                        (from i in db.ImageRosters
                         where i.UserID == ID
                         orderby i.Timestamp descending
                         select i).ToList<ImageRoster>();
                    return imageList;
                }
                catch (Exception)
                {
                    return null;
                }
            }
        }
    }
}